import 'package:flutter/material.dart';

class ExpansionPanelListDemo extends StatefulWidget {
  ExpansionPanelListDemo({Key key}) : super(key: key);

  _ExpansionPanelListDemoState createState() => _ExpansionPanelListDemoState();
}

class _ExpansionPanelListDemoState extends State<ExpansionPanelListDemo> {
  var currentPanelIndex = -1; // -1默认全部闭合
  List<int> mList;
  ExpansionPanelList _expansionPanelList;

  _ExpansionPanelListDemoState() {
    mList = new List();
    for (int i = 0; i < 3; i++) {
      mList.add(i);
    }
  }

  @override
  Widget build(BuildContext context) {
    _expansionPanelList = new ExpansionPanelList(
      animationDuration: Duration(milliseconds: 500),
      expansionCallback: (panelIndex, isExpanded) {
        setState(() {
          currentPanelIndex =
              (currentPanelIndex != panelIndex) ? panelIndex : -1;
        });
      },
      children: mList.map((i) {
        return new ExpansionPanel(
          headerBuilder: (context, isExpanded) {
            return new ListTile(
              title: new Text('panel - $i'),
            );
          },
          body: new Padding(
            padding: EdgeInsets.all(10.0),
            child: ListBody(
              children: <Widget>[
                new Text('panel body - $i'),
              ],
            ),
          ),
          isExpanded: currentPanelIndex == i,
        );
      }).toList(),
    );

    return Scaffold(
      appBar: AppBar(
        title: Text('BottomNavigationBar Sample'),
      ),
      body: Center(
        child: new ListView(
          children: <Widget>[
            new FlatButton(
              onPressed: null,
              child: new Text('date picker'),
            ),
            _expansionPanelList,
          ],
        ),
      ),
    );
  }
}
